package com.yhd.admin.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yhd.admin.bean.RoleFuncPriv;
import com.yhd.admin.mapper.RoleFuncPrivMapper;
import com.yhd.admin.utils.StringUtils;

@Service
public class RoleFuncPrivServiceImpl implements RoleFuncPrivService {
	@Autowired
	private RoleFuncPrivMapper roleFuncPrivMapper;
	
	@Override
	public List<RoleFuncPriv> getRoleFuncPrivByRoleId(int roleId) {
		return roleFuncPrivMapper.selectRoleFuncPrivByRoleId(roleId);
	}

	@Override
	public void deleteRoleFuncPrivByRoleId(int roleId) {
		roleFuncPrivMapper.deleteRoleFuncPrivByRoleId(roleId);
	}

	//权限修改
	@Override
	public void addRoleFuncPriv(int roleId, String funcIds) {
		roleFuncPrivMapper.deleteRoleFuncPrivByRoleId(roleId);
		String[] ids = funcIds.split(",");
		for(String id : ids){
			RoleFuncPriv rfp = new RoleFuncPriv();
			rfp.setRole_id(roleId);
			rfp.setFunc_id(StringUtils.convertInt(id));
			roleFuncPrivMapper.addRoleFuncPriv(rfp);
		}
	}

}
